import { axiosInstance } from 'src/boot/axios'
import CommonConfig from '../../assets/js/config'

import qs from 'qs'

const qsConfig = {
  arrayFormat: 'repeat',
  skipNulls: true,
  format: 'RFC3986'
}
const machinestatusUrl = CommonConfig.machinestatusUrl + '/v1'

export function getStopStatList ({ end, pageNum, pageSize, since, stopDurationEnd, stopDurationStart, stopTypeIds, deviceTreeReqVO }) {
  const newUrl = `${machinestatusUrl}/machine_reports/devices/stop_causes`
  let reqData = {
    params: {
      deviceTreeReqVO, end, pageNum, pageSize, since, stopDurationEnd, stopDurationStart, stopTypeIds
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 机台报表 停机明细导出
export function getExportExcel ({ deviceIds, end, excelHead, since, stopDurationEnd, stopDurationStart, stopTypeIds, requestId, deviceTreeReqVO }) {
  const newUrl = `${machinestatusUrl}/machine_reports/devices/stop_causes/excel:export`
  let reqData = {
    params: {
      deviceIds,
      end,
      excelHead,
      since,
      stopDurationEnd,
      stopDurationStart,
      stopTypeIds,
      requestId,
      deviceTreeReqVO
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 时间线导出
export function getExportTimeLine ({ date, pageNum, pageSize, requestId, deviceTreeReqVO, workshopId }) {
  const newUrl = `${machinestatusUrl}/machine/export_time_lines`
  let reqData = {
    params: {
      date,
      pageNum,
      pageSize,
      requestId,
      deviceTreeReqVO,
      workshopId
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
// 机台报表 停机明细修改
export function putBatchReport (list) {
  const newUrl = `${machinestatusUrl}/machine_reports/devices/stop_causes:batchReport`
  return axiosInstance.put(newUrl, list).then((res) => {
    return Promise.resolve(res)
  })
}
export function getEnergyStatList ({ endDate, pageNum, pageSize, startDate, deviceTreeReqVO }) {
  const newUrl = `${machinestatusUrl}/device_energy/list`
  let reqData = {
    params: {
      endDate, pageNum, pageSize, startDate, deviceTreeReqVO
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
export function exportEnergyStatList ({ endDate, pageNum, pageSize, startDate, deviceTreeReqVO, requestId }) {
  const newUrl = `${machinestatusUrl}/device_energy/export`
  let reqData = {
    params: {
      endDate, pageNum, pageSize, startDate, deviceTreeReqVO, requestId
    },
    paramsSerializer: function (params) {
      return qs.stringify(params, qsConfig)
    }
  }
  return axiosInstance.post(newUrl, reqData.params).then((res) => {
    return Promise.resolve(res)
  })
}
